import React, { Component } from 'react'
import './index.css'

export default class Footer extends Component {
	render() {
		const {todos} = this.props
		const doneCount = todos.reduce((pre,cur)=> pre + (cur.done ? 1 : 0),0)
		return (
			<div className="todo-footer">
				<label>
					<input type="checkbox" checked={todos.length === doneCount && todos.length>0} onChange={this.updateAll}/>
				</label>
				<span>
					<span>已完成{doneCount}</span> / 全部{todos.length}
				</span>
				<button onClick={this.deleteAllDone} className="btn btn-danger">清除已完成任务</button>
			</div>
		)
	}

	deleteAllDone = ()=>{
		this.props.deleteAllDoneTodo()
	}

	updateAll = (e)=>{
		this.props.updateAllTodo(e.target.checked)
	}

}
